package com.shiro.test.mvc.controller;

import com.shiro.test.mvc.pojo.LeaveApply;
import com.shiro.test.mvc.pojo.User;
import com.shiro.test.mvc.service.ILeaveApplyService;
import com.shiro.test.mvc.util.Constants;
import com.shiro.test.mvc.util.MessageUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2020/12/1 0001.
 */
@Controller
@RequestMapping("/system/task.html")
public class TaskController {

    @Autowired
    private ILeaveApplyService leaveApplyService;

    @RequestMapping(params = "act=page")
    public String taskList(){
        return "task_list";
    }
    @RequestMapping(params = "act=go_edit")
    public String goEdit(){
        return "task_edit";
    }


    @RequestMapping(params = "act=list")
    @ResponseBody
    public List<LeaveApply> list(){
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        User user = (User) session.getAttribute(Constants.SESSION_USER);
        List<LeaveApply> leaveTaskList = leaveApplyService.getLeaveTaskList(user.getId());
        return leaveTaskList;
    }

    @RequestMapping(params = "act=advise")
    @ResponseBody
    public Map<String,Object> advise(LeaveApply leaveApply){
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        User user = (User) session.getAttribute(Constants.SESSION_USER);
       leaveApplyService.updateTask(leaveApply,user.getId());
       return MessageUtil.getSuccessResult("处理成功");
    }

}
